﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace GSManager
{
    public class ChiPhi
    {
        private int _SoPhieuChi;
        private DateTime _NgayChi;
        private decimal _TongTien;
        private string _NguoiChi;
        public int SoPhieuChi
        {
            get { return _SoPhieuChi; }
            set { _SoPhieuChi = value; }
        }
        public DateTime NgayChi
        {
            get { return _NgayChi; }
            set { _NgayChi = value; }
        }
        public decimal TongTien
        {
            get { return _TongTien; }
            set { _TongTien = value; }
        }
        public string NguoiChi
        {
            get { return _NguoiChi; }
            set { _NguoiChi = value; }
        }
        public int DemSoPhieuChi()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select Count(SoPhieuChi) from PHIEUCHI";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            int kq = 0;
            while (r.Read())
            {
                try
                {
                    kq = (int)r[0];
                }
                catch (Exception) { }
            }
            r.Close();
            connect.Close();
            return kq;
        }
        public void LuuPhieu()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Insert into PHIEUCHI values(?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@SoPhieuChi", OleDbType.Integer);
            cmd.Parameters.Add("@NgayChi", OleDbType.Date);

            //cmd.Parameters.Add("@MaKhachHang", OleDbType.VarChar);
            cmd.Parameters.Add("@TongTienChi", OleDbType.Decimal);
            cmd.Parameters.Add("@NguoiChi", OleDbType.VarWChar);
            cmd.Parameters[0].Value = SoPhieuChi;
            cmd.Parameters[1].Value = NgayChi;
            cmd.Parameters[2].Value = TongTien;
            cmd.Parameters[3].Value = NguoiChi;
            //cmd.Parameters[4].Value = NguoiLapPhieu;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
    }
}
